package com.news.news.web;


import com.github.pagehelper.PageInfo;
import com.news.news.modle.Admin;
import com.news.news.modle.System;
import com.news.news.service.SystemService;
import com.news.news.util.CommonResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;

@Api(tags = "管理员登录控制器类的介绍")
@RestController
@RequestMapping(path = "/admin/systemCtl")
public class SystemController {
    @Resource
    SystemService systemService;

    @Value("logoimgPath")
    String logoimgPath;

    @RequestMapping(value = "/list")
    public CommonResult list() {
//        System.out.println(admin);
        System system1 = systemService.systemList();
        CommonResult commonResult = new CommonResult(200, system1, "成功");
        return commonResult;
    }


    //保存
    @RequestMapping(value = "/save")
    public CommonResult saveAdmin(@RequestBody System system, @RequestHeader("adminToken") String token) {
        systemService.save(system,token);
        CommonResult commonResult = new CommonResult(200, null, "成功");
        return commonResult;
    }
//
    //更新logo
    @RequestMapping(value = "/logosuplaod")
    public CommonResult logosuplaod(@RequestParam("file") CommonsMultipartFile file) throws IOException {
        String newfilename=new Date().getTime()+file.getOriginalFilename();
          String path="D:\\Program Files\\apache-tomcat-9.0.43\\webapps\\ROOT\\logoimg\\"+newfilename;
          file.transferTo(new File(path));
          String logo="logoimg\\"+newfilename;
          systemService.updateLogo(logo);
        CommonResult commonResult = new CommonResult(200,"logoimg\\"+newfilename, "上传成功");
        return commonResult;
    }
}
